package com.echoesnet.echoesshortvideo.Activities;

import android.media.Image;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.echoesnet.echoesshortvideo.AppController;
import com.echoesnet.echoesshortvideo.R;
import com.echoesnet.echoesshortvideo.Utils.Image.GlideApp;
import com.echoesnet.echoesshortvideo.views.video.EmptyControlVideo;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/**
 * Copyright (C) 2017 在线回声（天津）科技发展有限公司
 * 在线回声完全享有此软件的著作权，违者必究
 *
 * @author an
 * @version 1.0
 * @modifier
 * @createDate 2018/4/25 0025
 * @description
 */
public class PreviewVideoAct extends BaseActivity
{
    @BindView(R.id.emptyControlVideo)
    EmptyControlVideo emptyControlVideo;

    @BindView(R.id.img_thumbnail)
    ImageView imgThumbnail;
    @BindView(R.id.img_play)
    ImageView imgPlay;

    private String mVideoPath;
    private String thumbnailPath;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preview_video_act);
        ButterKnife.bind(this);
        mVideoPath = getIntent().getStringExtra("path");
        thumbnailPath = getIntent().getStringExtra("thumbnailPath");
        VideoOptionModel videoOptionModel = new VideoOptionModel(tv.danmaku.ijk.media.player.IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1);
        VideoOptionModel videoOptionModel1 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 5);
        List<VideoOptionModel> list = new ArrayList<>();
        list.add(videoOptionModel);
        list.add(videoOptionModel1);
        GSYVideoManager.instance().setOptionModelList(list);
        GlideApp.with(AppController.getInstance())
                .asBitmap()
                .load(thumbnailPath)
                .into(imgThumbnail);
        if (!TextUtils.isEmpty(mVideoPath))
        {
            emptyControlVideo.setLooping(true);
            emptyControlVideo.setUp(mVideoPath,false,null);
            emptyControlVideo.startPlayLogic();
            emptyControlVideo.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View view)
                {
                    finish();
                }
            });
            emptyControlVideo.setVideoAllCallBack(new GSYSampleCallBack()
            {
                @Override
                public void onAutoComplete(String url, Object... objects)
                {
                    super.onAutoComplete(url, objects);
                }
            });
        }
        imgPlay.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                emptyControlVideo.startPlayLogic();
                imgPlay.setVisibility(View.GONE);
            }
        });

    }

    @Override
    protected void onDestroy()
    {
        emptyControlVideo.release();
        super.onDestroy();
    }
}
